package com.sf.service.impl;

import com.alibaba.druid.pool.DruidDataSource;
import com.sf.domain.Department;
import com.sf.mapper.DepartmentMapper;
import com.sf.mapper.EmployeeMapper;
import com.sf.qo.EmployeeQueryObject;
import com.sf.qo.QueryObject;
import com.sf.service.IDepartment;
import com.sf.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.sql.DataSource;
import java.util.Collections;
import java.util.List;

@Service
public class DepartmentImpl implements IDepartment {

    public void setDepartmentMapper(DepartmentMapper departmentMapper) {
        this.departmentMapper = departmentMapper;
    }

    @Autowired
    private DepartmentMapper departmentMapper;


    @Override
    public void deleteByPrimaryKey(Long id) {
        departmentMapper.deleteByPrimaryKey(id);


    }

    @Override
    public void insert(Department department) {

        departmentMapper.insert(department);
    }

    @Override
    public void updateByPrimaryKey(Department department) {
        if(department.getId() == null){
            departmentMapper.insert(department);
        }else{
            departmentMapper.updateByPrimaryKey(department);
        }


    }

    @Override
    public Department selectByPrimaryKey(Long id) {
        departmentMapper.selectByPrimaryKey(id);
        return null;
    }

    @Override
    public List<Department> selectAll() {
        departmentMapper.selectAll();
        return Collections.emptyList();
    }

    @Override
    public PageResult<Department> query(EmployeeQueryObject qo) {
        int count = departmentMapper.selectForCount(qo);
        if(count == 0) {
            return new PageResult<>(qo.getCurrentPage(), qo.getPageSize(),null
                    , 1);
        }
        return new PageResult<>(qo.getCurrentPage(), qo.getPageSize(), departmentMapper.selectForList(qo)
                ,count);
    }

    @Override
    public Department get(Long id) {
        departmentMapper.get(id);
        return departmentMapper.get(id);
    }



}
